package com.yonyou.gmmc.service.wechatpush.event.service;

import static org.marketing.common.constants.MessagePushConstant.WX_MSG_PROP_COLOR;
import static org.marketing.common.constants.MessagePushConstant.WX_MSG_PROP_URL;

import org.marketing.common.constants.BusinessConstant;
import org.marketing.common.constants.MessagePushConstant;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageTemplateContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolReceiver;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolSender;
import org.marketing.common.event.EventMaintainChangedDTO;
import org.marketing.common.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class MaintainAppointmentConfirmService {

	private static Logger logger = LoggerFactory.getLogger(MaintainAppointmentConfirmService.class);
	public WeChatMessageProtocol getWXTemplate(EventMaintainChangedDTO o){
        WeChatMessageProtocol messageProtocol = new WeChatMessageProtocol();

        WeChatMessageProtocolReceiver receiver = new WeChatMessageProtocolReceiver();
        receiver.setDetail(true);
        receiver.setPlatform(MessagePushConstant.PUSH_PLATFORM.WC_PUBLIC);
        receiver.addDetailList(o.getOpenId());//"omLPIwITFcilUn_u5EPrINDwFlPg"陈春周
        WeChatMessageProtocolMessageContent message = new WeChatMessageProtocolMessageContent();
        //养修预约确认提醒
        message.setContent("TM00627");
        message.addExtraParaMap(WX_MSG_PROP_URL,o.getUrl());
        
        message.setSourceType(BusinessConstant.SOURCE_TYPE_WECHAT);

        WeChatMessageProtocolMessageTemplateContent content1 = new WeChatMessageProtocolMessageTemplateContent();
        content1.setKey("first");
        content1.setValue(o.getFirstTitle());
        content1.addExtraMap(WX_MSG_PROP_COLOR,"#FF0000");
        message.addTemplateConentList(content1);

        WeChatMessageProtocolMessageTemplateContent content2 = new WeChatMessageProtocolMessageTemplateContent();
        content2.setKey("keynote1"); 
        content2.setValue(o.getModelName());
        message.addTemplateConentList(content2);

        WeChatMessageProtocolMessageTemplateContent content3 = new WeChatMessageProtocolMessageTemplateContent();
        content3.setKey("keynote2");//DateUtil.formateDate(new Date(), "yyyy-MM-dd HH:mm:ss")
        content3.setValue(o.getAppointType());
        message.addTemplateConentList(content3);

        WeChatMessageProtocolMessageTemplateContent content4 = new WeChatMessageProtocolMessageTemplateContent();
        content4.setKey("keynote3");
        content4.setValue(DateUtil.formateDate(o.getStartTime(),"yyyy-MM-dd HH:mm:ss"));
        message.addTemplateConentList(content4);

        WeChatMessageProtocolMessageTemplateContent content5 = new WeChatMessageProtocolMessageTemplateContent();
        content5.setKey("keynote4");
        content5.setValue(""+o.getMaintainMileage());
        message.addTemplateConentList(content5);

        
        WeChatMessageProtocolMessageTemplateContent content6 = new WeChatMessageProtocolMessageTemplateContent();
        content6.setKey("remark");
        String remark = o.getRemark().replaceAll("&lt;", "<").replaceAll("&gt;", ">");
        content6.setValue(remark);
        message.addTemplateConentList(content6);

        WeChatMessageProtocolSender sender = new WeChatMessageProtocolSender();
        sender.setOriginApplicationHost("host1");
        sender.setOriginApplicationName("app1");
        sender.setClientAppId("wxb85ed633e428bafc");
        sender.setDealerCode("270001");
        messageProtocol.setMessage(message);
        messageProtocol.setReceiver(receiver);
        messageProtocol.setSender(sender);
        messageProtocol.setPushChannel(MessagePushConstant.PUSH_CHANNEL.WEBCHAT);

        return messageProtocol;
   }
}
